using System.Collections;

namespace Coding4Fun.BluetoothPanoHead
{
    /// <summary>
    /// A Queue() container that can dump the buffer when the STOP command comes in
    /// </summary>
    public class CommandQueue
    {
        private readonly Queue _queue = new Queue();
        public int Count
        {
            get
            {
                return _queue.Count;
            }
        }

        public ControlCommand Dequeue()
        {
            return (ControlCommand)(_queue.Dequeue());
        }

        /// <summary>
        /// Appends a new command the queue.  If the new command is the STOP command, all previous commands are dumped
        /// </summary>
        /// <param name="value">Current ControlCommand to append to the queue.</param>
        public void Enqueue(ControlCommand value)
        {
		    if (value.Action.Equals(Commands.CMD_STOP))
		    {
			    _queue.Clear();
		    }
            _queue.Enqueue(value);
        }
    }
}
